package com.wc.acwing.思维.翻转;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/23 11:09
 * @description https://www.acwing.com/problem/content/4970/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static String s, t;
    static int n;

    /***
     * 思路：
     * 性质1： 11 和 00 是无法操作的
     * 性质2： 101 和 010 变成111 000 是不可逆的，参照性质1
     * 性质3： 操作的顺序对结果没有影响，参照性质2
     *
     * 我们可以从所有操作的选择从左到右出发的操作即可，参照性质3
     * s[i] == t[i] 一定不用操作
     * s[i] != t[i] 一定需要操作
     */
    public static void main(String[] args) {
        n = sc.nextInt();

        while (n-- > 0) {
            t = sc.next();
            s = sc.next();
            int len = s.length();
            char[] chs = s.toCharArray();
            char[] cht = t.toCharArray();
            int res = 0;
            for (int i = 0; i < len; i++) {
                if (chs[i] != cht[i]) {
                    if (i == 0 || i == len - 1 || chs[i] == chs[i - 1] || chs[i] == chs[i + 1]) {
                        res = -1;
                        break;
                    }
                    res++;
                    chs[i] = cht[i];
                }
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
